package cn.jdx.config;

import cn.jdx.interceptor.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    //视图解析器
    public void addViewControllers(ViewControllerRegistry registry) {
        //访问 xxx,aaa,bbb 的时候会重定向到 index.html
//        registry.addViewController("/index").setViewName("index");
        System.out.println("视图");
    }

    //重写这个方法：
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/**")//拦截所有的控制器请求
                .excludePathPatterns("/index.html","/","/css/**","/js/**","/img/**");
    }

}
